11/4/2022

US Population from 1790 to 1970

This code shows data with the US population (in millions) from 1790 to 1970. We will plot this data with the plotly package.

data(uspop)
data <- data.frame(uspop)
data$year <- seq(1790,1970,by=10)
head(data)
  uspop year
1  3.93 1790
2  5.31 1800
3  7.24 1810
4  9.64 1820
5 12.90 1830
6 17.10 1840

US Population from 1790 to 1970

This code generates the plot.

library(ggplot2)
library(plotly)
library(dplyr)
library(tidyr)
fig <- plot_ly(data = data,x = ~year,y = ~uspop,
      type = "scatter",
      mode="lines",
      line = list(color="green",width=3))
fig <- fig %>% layout(title = "US Population by Year",
      xaxis = list(title = "Year"),
      yaxis = list(title = "US Population (in millions)"))

US Population from 1790 to 1970

Here is the plot!